/*
 * NouProg_Form.java
 *
 * Created on __DATE__, __TIME__
 */

package cobolinfo;

import java.util.ArrayList;

import cobolinfo.FileControler;

/**
 * 
 * @author __USER__
 */
public class NouProgForm extends javax.swing.JDialog {

	private FileControler mFileControl = new FileControler();

	/** Creates new form NouProg_Form */
	public NouProgForm(java.awt.Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jFormattedTextField1 = new javax.swing.JFormattedTextField();
		jButton1 = new javax.swing.JButton();
		jTextFieldMantis = new javax.swing.JTextField();
		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jTextFieldProg = new javax.swing.JTextField();
		jLabel3 = new javax.swing.JLabel();
		jLabel4 = new javax.swing.JLabel();
		jLabel5 = new javax.swing.JLabel();
		jTextFieldUser = new javax.swing.JTextField();
		jLabel6 = new javax.swing.JLabel();
		jTextFieldCom = new javax.swing.JTextField();
		jButton2 = new javax.swing.JButton();
		jButton3 = new javax.swing.JButton();
		jTextDateIn = new javax.swing.JTextField();
		jTextDateEnd = new javax.swing.JTextField();

		jFormattedTextField1.setText("jFormattedTextField1");

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		jButton1.setText("GUARDAR");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		jLabel1.setText("Mantis");

		jLabel2.setText("Programa");

		jLabel3.setText("Fecha inicio (DD/MM/AAAA)");

		jLabel4.setText("Fecha fin (DD/MM/AAAA)");

		jLabel5.setText("Usuario");

		jLabel6.setText("Comentario");

		jButton2.setText("...");
		jButton2.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton2ActionPerformed(evt);
			}
		});

		jButton3.setText("...");
		jButton3.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton3ActionPerformed(evt);
			}
		});

		jTextDateIn.setEditable(false);

		jTextDateEnd.setEditable(false);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jLabel3)
																				.addComponent(
																						jLabel4)
																				.addComponent(
																						jLabel2)
																				.addComponent(
																						jLabel1)
																				.addComponent(
																						jLabel5)
																				.addComponent(
																						jLabel6))
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING,
																				false)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																										91,
																										Short.MAX_VALUE)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.TRAILING,
																												false)
																												.addComponent(
																														jTextDateEnd)
																												.addComponent(
																														jTextDateIn,
																														javax.swing.GroupLayout.DEFAULT_SIZE,
																														79,
																														Short.MAX_VALUE))
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING,
																												false)
																												.addComponent(
																														jButton2,
																														0,
																														0,
																														Short.MAX_VALUE)
																												.addComponent(
																														jButton3,
																														javax.swing.GroupLayout.PREFERRED_SIZE,
																														46,
																														javax.swing.GroupLayout.PREFERRED_SIZE)))
																				.addComponent(
																						jTextFieldMantis)
																				.addComponent(
																						jTextFieldProg,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						222,
																						Short.MAX_VALUE)
																				.addComponent(
																						jTextFieldUser)
																				.addComponent(
																						jTextFieldCom)))
												.addComponent(jButton1))
								.addContainerGap(
										javax.swing.GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.BASELINE)
																				.addComponent(
																						jTextDateIn,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jButton2))
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.BASELINE)
																				.addComponent(
																						jButton3)
																				.addComponent(
																						jTextDateEnd,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.PREFERRED_SIZE)))
												.addGroup(
														javax.swing.GroupLayout.Alignment.TRAILING,
														layout.createSequentialGroup()
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																		8,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addComponent(
																		jLabel3)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(
																		jLabel4)
																.addGap(10, 10,
																		10)))
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel2)
												.addComponent(
														jTextFieldProg,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel1)
												.addComponent(
														jTextFieldMantis,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel5)
												.addComponent(
														jTextFieldUser,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel6)
												.addComponent(
														jTextFieldCom,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(18, 18, 18)
								.addComponent(jButton1)
								.addContainerGap(
										javax.swing.GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));

		jTextFieldMantis.getAccessibleContext().setAccessibleName(
				"jTextFieldPack");
		jTextFieldProg.getAccessibleContext().setAccessibleName(
				"jTextFieldProg");
		jTextFieldUser.getAccessibleContext().setAccessibleName(
				"jTextFieldUser");
		jTextFieldCom.getAccessibleContext().setAccessibleName("jTextFieldCom");
		jTextDateIn.getAccessibleContext().setAccessibleName("jTextDateIn");
		jTextDateIn.getAccessibleContext().setAccessibleDescription(
				"jTextDateIn");
		jTextDateEnd.getAccessibleContext().setAccessibleName("jTextDateEnd");
		jTextDateEnd.getAccessibleContext().setAccessibleDescription(
				"jTextDateEnd");

		pack();
	}// </editor-fold>
		// GEN-END:initComponents

	private void Guardar() {
		String separator = this.mFileControl.mSeparator;
		ArrayList<String> fields = new ArrayList<String>();
		fields.add(jTextDateIn.getText());
		fields.add(jTextDateEnd.getText());
		fields.add(jTextFieldProg.getText());
		fields.add(jTextFieldMantis.getText());
		fields.add(jTextFieldUser.getText());
		fields.add(jTextFieldCom.getText());
		String txt = "";
		boolean any = false;
		for (String f : fields) {
			if (f != "") {
				any = true;
			}
			if (txt != "") {
				txt += separator;
			}
			txt += f;
		}
		if (any) {
			this.mFileControl.WriteHistoryFile(txt);
		}
		this.Close();
	}

	private void Close() {
		NouProgForm.this.dispose();
	}

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
		this.Guardar();
	}

	private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
		CalendarForm ca = new CalendarForm("/", this.jTextDateEnd);
		ca.setTitle("Fin");
		ca.pack();
		ca.setVisible(true);
		ca.setModal(true);
		ca.toFront();
	}

	private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
		CalendarForm ca = new CalendarForm("/", this.jTextDateIn);
		ca.setTitle("Inicio");
		ca.pack();
		ca.setVisible(true);
		ca.setModal(true);
		ca.toFront();
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				NouProgForm dialog = new NouProgForm(new javax.swing.JFrame(),
						true);
				dialog.addWindowListener(new java.awt.event.WindowAdapter() {
					public void windowClosing(java.awt.event.WindowEvent e) {
						System.exit(0);
					}
				});
				dialog.setVisible(true);
			}
		});
	}

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton jButton1;
	private javax.swing.JButton jButton2;
	private javax.swing.JButton jButton3;
	private javax.swing.JFormattedTextField jFormattedTextField1;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JTextField jTextDateEnd;
	private javax.swing.JTextField jTextDateIn;
	private javax.swing.JTextField jTextFieldCom;
	private javax.swing.JTextField jTextFieldMantis;
	private javax.swing.JTextField jTextFieldProg;
	private javax.swing.JTextField jTextFieldUser;
	// End of variables declaration//GEN-END:variables

}